//
//  CDCell.m
//  CarLife
//
//  Created by yu on 2019/4/2.
//  Copyright © 2019年 jpas. All rights reserved.
//

#import "CDCell.h"
#import "PhotosContainerView.h"
#import "CommunityModel.h"

@implementation CDCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UIView *contentView = self.contentView;
    
    _iconImgView.sd_layout
    .leftSpaceToView(contentView, 16)
    .topSpaceToView(contentView, 16)
    .widthIs(kAutoWidth(36))
    .heightEqualToWidth();
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconTapAction:)];
    [_iconImgView addGestureRecognizer:tap];
    
    _nicknameLabel.sd_layout
    .leftSpaceToView(_iconImgView, 11)
    .topEqualToView(_iconImgView)
    .heightIs(20);
    [_nicknameLabel setSingleLineAutoResizeWithMaxWidth:200];
    
    _timeLabel.sd_layout
    .leftEqualToView(_nicknameLabel)
    .bottomEqualToView(_iconImgView)
    .heightIs(17);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:200];
    
    _contentLabel.sd_layout
    .leftEqualToView(_iconImgView)
    .rightSpaceToView(contentView, 16)
    .topSpaceToView(_iconImgView, 10)
    .autoHeightRatio(0);
    
    _photosContainer.sd_layout
    .leftEqualToView(_iconImgView)
    .topSpaceToView(_contentLabel, 10)
    .rightEqualToView(_contentLabel);
    
}

- (void)iconTapAction:(UITapGestureRecognizer *)sender {
    if (self.iconTapBlock) {
        self.iconTapBlock();
    }
}


- (void)setCModel:(CommunityModel *)cModel
{
    _cModel = cModel;
    
    _nicknameLabel.text = cModel.nickname;
    _timeLabel.text = cModel.time;
    _contentLabel.text = cModel.content;
    _iconImgView.image = [UIImage imageNamed:cModel.iconUrl];
    
    UIView *bottomView;
    
    if (cModel.picNamesArray.count > 0) {
        bottomView = _photosContainer;
        _photosContainer.hidden = NO;
        _photosContainer.photoNamesArray = cModel.picNamesArray;
    } else {
        bottomView = _contentLabel;
        _photosContainer.hidden = YES;
    }
    
    [self setupAutoHeightWithBottomView:bottomView bottomMargin:10];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
